# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName : zsj.py
# @Time     : 2024/4/12 23:56
# @Author   : Robot-Zsj
"""
description:

i:
50
6
put a 10
put b 20
get a
get a
get b
put c 30

o:
a,c
"""


class Node:
    def __init__(self, key, val, freq):
        self.key = key
        self.val = val
        self.freq = freq
        self.prev = None
        self.next = None


class Link:
    def __init__(self):
        self.size = 0
        self.head = None
        self.tail = None

    def addLast(self, node):
        if self.size == 0:
            self.head = node
            self.tail = node
        else:
            self.tail.next = node
            node.prev = self.tail
            self.tail = node
        self.size += 1

    def remove(self, node):
        if self.size == 0:
            return
        if self.size == 1:
            self.head = None
            self.tail = None
        elif self.head == node:
            self.head = self.head.next
            self.head.prev = None
        elif self.tail == node:
            self.tail = self.tail.prev
            self.tail.next = None
        else:
            node.prev.next = node.next
            node.next.prev = node.prev

        self.size -= 1


class LRUCache:
    def __init__(self, capacity):
        self.keyMap = {}
        self.freqMap = {}
        self.capacity = capacity
        self.minFreq = 0

    def get(self, key):
        if key not in self.keyMap:
            return

        node = self.keyMap[key]
        self.incNodeFreq(node)

    def put(self, key, val):
        if key in self.keyMap:
            return

        while self.capacity < val:
            if self.minFreq == 0:
                return

            minFreqLink = self.freqMap[self.minFreq]

            removeNode = minFreqLink.head

            self.capacity += removeNode.val

            minFreqLink.remove(removeNode)
            self.keyMap.pop(removeNode.key)

            if minFreqLink.size == 0:
                del self.freqMap[self.minFreq]

                if len(self.freqMap.keys()) > 0:
                    self.minFreq = min(self.freqMap.keys())
                else:
                    self.minFreq = 0

        self.capacity -= val
        self.minFreq = 1
        node = Node(key, val, self.minFreq)

        self.freqMap.setdefault(self.minFreq, Link())
        self.freqMap.get(self.minFreq).addLast(node)
        self.keyMap[key] = node

    def incNodeFreq(self, node):
        self.freqMap[node.freq].remove(node)

        if self.freqMap[node.freq].size == 0:
            del self.freqMap[node.freq]

            if node.freq == self.minFreq:
                self.minFreq += 1
        node.freq += 1

        self.freqMap.setdefault(node.freq, Link())
        self.freqMap[node.freq].addLast(node)


m = int(input())

lfu = LRUCache(m)

n = int(input())

for _ in range(n):
    operation = input().split()

    op = operation[0]
    fileName = operation[1]

    if "put" == op:
        fileSize = int(operation[2])
        lfu.put(fileName, fileSize)
    else:
        lfu.get(fileName)

if lfu.capacity == m:
    print("NONE")
else:
    ans = list(lfu.keyMap.keys())
    ans.sort()
    print(",".join(ans))
